<template>
  <div class="conMain" >
    <el-card  class="box-card" >
      <div slot="header" class="topfix">
          <el-form   :inline="true"  :model="params" size="small" class="goodsForm"  label-width="100px">

              <el-form-item label="所属渠道">
                  <el-select  filterable clearable v-model="params.s_pass_id"  placeholder="请选择">
                      <el-option   :label="item.name" :value="item.id" v-for="(item,index) in passlist" />
                  </el-select>
              </el-form-item>
              <el-form-item label="同步时间" prop="s_exctime">
                  <el-date-picker
                      v-model="params.s_exctime"
                      type="daterange"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                  />
              </el-form-item>

              <el-form-item label=" ">
                <el-button type="primary"  size="small" class="searchBtn" @click="handleSearch" icon='el-icon-search'>搜索</el-button>
                <el-button type="danger" v-has="'task/cleardata'"  size="small"  @click="clearData" >清除任务记录</el-button>

              </el-form-item>
          </el-form>

      </div>
      <el-table v-loading="loading"  :data="list" style="width: 100%" :empty-text='emtypetxt'>
          <el-table-column prop="id" label="序号" align="center" width="100" />
          <el-table-column prop="exctime" label="同步时间" align="center"  />
          <el-table-column prop="pass_id" label="渠道ID" :show-overflow-tooltip="true" align="center"  />
          <el-table-column prop="passage.name" label="渠道名称" align="center"  />
          <el-table-column prop="num" label="同步单量" :show-overflow-tooltip="true" align="center"  />
          <el-table-column prop="zxtime" label="同步秒数" :show-overflow-tooltip="true" align="center"  />
          <el-table-column prop="msg" label="备注" :show-overflow-tooltip="true" align="center"  />

      </el-table>
      <div class="pagination">
          <el-pagination
            :current-page="params.page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="params.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
      </div>
    </el-card>

  </div>
</template>

<script>

import { task_index,task_clear } from  '@/api/service'
import { passage_list } from  '@/api/passage'


export default {
  data() {
    return {
      total:0,
      loading:true,
      emtypetxt:'',
      list: [],
      passlist:[],//渠道列表
      params: {
        s_pass_id:'',
        s_createtime:'',
        ss_createtime:'BETWEEN',
        page: 1,
        pagesize:10,
      },
    }
  },
  created() {
    passage_list().then(res => {
      this.passlist=res.data
    })
    this.getList()
  },
  methods: {
    getList(page) {
      this.params.page = page?page:this.params.page;
      this.emtypetxt='加载中...';
      this.loading=true;
      task_index(this.params).then(res => {
        this.list=res.data.list
        this.total=res.data.total
        this.loading = false
        if(this.list.length==0){
          this.emtypetxt='暂无数据'
        }
      })
    },

    handleSearch(){
      this.getList(1)
    },
    //分页
    handleSizeChange(val) {
      this.params.pagesize = val
      this.getList(1)
    },
    handleCurrentChange(val) {
      this.params.page = val
      this.getList()
    },
    clearData(){
      let _this=this;
      _this.$modalSure('您确定要清除3天前任务记录嘛？').then(() => {
        task_clear().then(res => {
          _this.$message.success(res.msg)
          _this.getList()
        })
      })
    }

  },
}
</script>

<style lang="scss" scoped>


</style>
